package com.test.controller;

import com.google.common.eventbus.EventBus;
import com.test.eventbus.EventObject;
import com.test.eventbus.FirstEvent;
import com.test.eventbus.SecondEvent;
import com.test.mysqlseq.service.SeqService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloWorldController {

    @RequestMapping("/sp")
    public String hello() {
        return "SpringBoot2.0";
    }


    @Autowired
    private EventBus eventBus;

    @RequestMapping("/test")
    public void test(){
        EventObject object = new EventObject(1,"setest");
        FirstEvent fevt = new FirstEvent(2, "first event");
        SecondEvent sevt = new SecondEvent(3, "second event");
        eventBus.post(object);
        eventBus.post(sevt);
        eventBus.post(fevt);
    }

    @Autowired
    private SeqService seqService;

    @GetMapping(value = "/seq")
    public Object getSeq(int c) {
        String[] seqs = new String[c];
        for (int i = 0; i < c; i++) {
            seqs[i] = seqService.getOutPatientCode(3L);
        }
        return seqs;
    }

    @RequestMapping("/test1")
    public void test1(){
        EventObject object = new EventObject(1,"setest");
        eventBus.post(object);
    }
}
